#!/bin/bash
set -e

echo "=== Gitaly Tools Archive-Keeparound 子命令测试 ==="

# 检查是否在正确的目录
if [ ! -f "main.go" ] || [ ! -f "archive.go" ]; then
    echo "错误: 请在cmd/gitaly-tools目录中运行此脚本"
    exit 1
fi

echo "1. 测试编译..."
go build -o gitaly-tools-test . || {
    echo "错误: 编译失败"
    exit 1
}
echo "   ✓ 编译成功"

echo ""
echo "2. 测试帮助信息..."
./gitaly-tools-test archive-keeparound -h 2>&1 | head -10 || {
    echo "错误: 获取帮助信息失败"
    exit 1
}
echo "   ✓ 帮助信息显示正常"

echo ""
echo "3. 测试参数验证..."
# 测试缺少必需参数的情况
./gitaly-tools-test archive-keeparound 2>&1 | grep -q "config路径不能为空" && {
    echo "   ✓ 参数验证正常"
} || {
    echo "   ✗ 参数验证可能有问题"
}

echo ""
echo "4. 测试主程序帮助..."
./gitaly-tools-test -h 2>&1 | grep -q "archive-keeparound" && {
    echo "   ✓ 子命令在主帮助中显示正常"
} || {
    echo "   ✗ 子命令未在主帮助中显示"
}

echo ""
echo "5. 清理测试文件..."
rm -f gitaly-tools-test
echo "   ✓ 清理完成"

echo ""
echo "=== 测试完成 ==="
echo "新的 archive-keeparound 子命令基本功能正常！"
echo ""
echo "使用示例:"
echo "  gitaly-tools archive-keeparound \\"
echo "    -config=/path/to/config.toml \\"
echo "    -repository-path=group/project.git \\"
echo "    -dry-run"
